﻿#pragma once

#include <QTimer>
#include "chromatogramChart.h"
#include "algorithm.h"
#include "GetMessageInterface.h"

class ChromatogramManager : public QObject{

    Q_OBJECT

public:
    ChromatogramManager();

    Q_INVOKABLE void onStartExperiment();
    Q_INVOKABLE void onEndExperiment();

    Q_INVOKABLE void setDetectMode(int isAuto, int autoType, int thr, int delayTimeCollect, int timeCollect, int delayTimeStop);
    Q_INVOKABLE void setDetectMode(int isAuto);
    Q_INVOKABLE void setThreshold(int thr);
    Q_INVOKABLE QVariantMap getDetectMode();

    // 和外部内容的接口
    ChromatogramChart*      _chart = nullptr;
    GetMessageInterface     *_msgInterface = nullptr;



signals:
    void sigStartCollect();
    void sigEndCollect();

public slots:

    void refresh();         // 秒间隔触发，执行计算
    void onCollectStop();


private:

    void refreshPointList();

    void judgeCollectState();
    bool judgeCollectStateByThr();
    bool judgeCollectStateByPeak();
    bool judgeCollectCloseStateByThr();



private:
    // 模式
    int  _isAuto = 0;               // 0自动 1手动
    int  _autoType = 0;             // 0阈值+指定收集时间 1峰值+指定收集时间 2阈值+低于阈值时停止收集
    int  _threshold = 300;          // 阈值在开启实验之后就不能手动调了吧……
    int  _delayTimeCollect = 1;     // 开始延迟时间(s)
    int  _timeCollect = 120;        // 产物接收时间(s)
    int  _delayTimeStop = 0;        // 关闭检测延迟时间(s)


    // 数据
    QVector<QPointF>    _pointList_raw;
    QVector<QPointF>    _pointList_filter;


    QTimer*      _timer_tick;           //
    QTimer*      _timer_collect;        // 统计收集的时间


    // 临时数据
    bool        _hasRise = false;
    bool        _hasCollect = false;

};
